# encoding=utf-8
from LBT.BaseParent.BaseLbt import lbtlogin
from LBT.Resource.SchoolStationAtt import SchoolStationAtt
import os, time


class SchoolIntroduce(lbtlogin, SchoolStationAtt):
    """园所简介模块
    1、查看园所页面，并数据库校验图片及改动后的文字
    """

    @lbtlogin.loginFun
    def test_schoolintroduce(self):
        """
        查看园所页面，并数据库校验图片及改动后的文字
        :return:
        """
        self.docstr ='查看园所页面，并数据库校验图片及改动后的文字'
        dr = self.driver
        self.moduleOp.openMoudleAndIn(self.schoolstation_navigation_class, self.schoolstation_introduce_url)
        """先验证页面加载对不对"""
        self.assertTrue(dr.find_element_by_xpath(self.schoolstation_introduce_title_xpath).is_displayed())
        self.assertTrue(dr.find_element_by_id(self.schoolstation_introduce_photo_id).is_displayed())
        self.assertTrue(dr.find_element_by_name(self.schoolstation_introduce_text_name).is_displayed())
        self.assertTrue(dr.find_element_by_xpath(self.schoolstation_introduce_save_xpath).is_displayed())
        """
        1、获取旧有的照片地址和简介内容。
        2、替换照片和文字为指定内容。
        3、数据库校验。
        4、替换回来并校验
        """
        oldphotourl = dr.find_element_by_id(self.schoolstation_introduce_photo_id).get_property("src")
        oldtext = dr.find_element_by_name(self.schoolstation_introduce_text_name).text
        dr.find_element_by_id(self.schoolstation_introduce_upload_id).click()
        """获取resource的目录路径，照片资源放在了Resource下面"""
        resourcepath = self.getDir(__file__, 3) + "\\Resource\\"
        self.downloadimg(oldphotourl, resourcepath, 'old')
        newimgpath = resourcepath + "beautiful.jpg"
        os.system(resourcepath + "openimg.exe  " + newimgpath)
        time.sleep(5)
        self.clearAndSendKeyForText(dr.find_element_by_name(self.schoolstation_introduce_text_name),
                                    self.getCurrentTime(),dr)
        dr.find_element_by_xpath(self.schoolstation_introduce_save_xpath).click()
        newphotourl = dr.find_element_by_id(self.schoolstation_introduce_photo_id).get_property("src")
        newtext = dr.find_element_by_name(self.schoolstation_introduce_text_name).text
        self.assertTrue(self.selectlbt(
            "select schoolinfo from school where schoolname = '" + self.lbt_schoolname_text + "'") == newtext)
        self.assertTrue(self.selectlbt(
            "select schoollogo from school where schoolname = '" + self.lbt_schoolname_text + "'") == newphotourl)

        dr.find_element_by_id(self.schoolstation_introduce_upload_id).click()
        oldimgpath = resourcepath + "old.jpg"
        os.system(resourcepath + "openimg.exe  " + oldimgpath)
        time.sleep(5)
        self.clearAndSendKeyForText(dr.find_element_by_name(self.schoolstation_introduce_text_name),
                                    oldtext,dr)
        dr.find_element_by_xpath(self.schoolstation_introduce_save_xpath).click()
        currentphotourl = dr.find_element_by_id(self.schoolstation_introduce_photo_id).get_property("src")
        currenttext = dr.find_element_by_name(self.schoolstation_introduce_text_name).text
        self.assertTrue(self.selectlbt(
            "select schoolinfo from school where schoolname = '" + self.lbt_schoolname_text + "'") == currenttext)
        self.assertTrue(self.selectlbt(
            "select schoollogo from school where schoolname = '" + self.lbt_schoolname_text + "'") == currentphotourl)
